#include "StdAfx.h"
#include "Victory.h"

#include "IRaceController.h"
#include "AnimatedImage.h"
#include "RenderingManager.h"
#include "MeshStorage.h"


///////////////////////////////////////////////////////////////////////////////

Victory::Victory(IRaceController& raceController,
                 IRenderingManager& renderingManager,
                 IMeshStorage& meshStorage)
      : m_raceController(raceController),
      m_renderingManager(renderingManager),
      m_victoryText(meshStorage.getVictoryScreen()),
      m_defeatText(meshStorage.getDefeatScreen()),
      m_displayedImage(NULL),
      m_time(0)
{
   float w = m_victoryText.getWidth();
   m_victoryText.setPosition(0.5f - w / 2.f, 0.1f);

   w = m_defeatText.getWidth();
   m_defeatText.setPosition(0.5f - w / 2.f, 0.1f);
}

///////////////////////////////////////////////////////////////////////////////

Victory::~Victory(void)
{
}

///////////////////////////////////////////////////////////////////////////////

void Victory::update(float timeElapsed)
{
   m_time -= timeElapsed;

   if (m_time <= 0)
   {
      m_raceController.raceOver();
   }
}

///////////////////////////////////////////////////////////////////////////////

void Victory::activate()
{
   if (m_raceController.hasPlayerWon())
   {
      m_displayedImage = &m_victoryText;
   }
   else
   {
      m_displayedImage = &m_defeatText;
   }

   m_renderingManager.startRendering(*m_displayedImage);
   m_time = 5;
}

///////////////////////////////////////////////////////////////////////////////

void Victory::deactivate()
{
   m_renderingManager.stopRendering(*m_displayedImage);
   m_displayedImage = NULL;
}

///////////////////////////////////////////////////////////////////////////////

void Victory::processInput(UCHAR* keyBuffer, float timeElapsed)
{
}

///////////////////////////////////////////////////////////////////////////////
